﻿/**
 * ForumServiceImpl.java 1.0 2007-4-22 上午03:11:45,创建 by yangfan
 */


package org.in4j.bbs.service.impl;

import java.util.List;

import org.hibernate.Hibernate;
import org.hibernate.Query;
import org.in4j.bbs.dao.BoardDao;
import org.in4j.bbs.model.Board;
import org.in4j.bbs.model.Category;
import org.in4j.bbs.service.ForumService;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 *
 * @author yangfan
 * @version 1.0 2007-4-22 上午03:11:45,创建
 */
public class ForumServiceImpl extends HibernateDaoSupport implements ForumService
{
	private JdbcTemplate jdbcTemplate;
	private BoardDao boardDao;

	public void setJdbcTemplate(JdbcTemplate jdbcTemplate)
	{
		this.jdbcTemplate = jdbcTemplate;
	}

	public int getPostCount()
	{
		return jdbcTemplate.queryForInt("select count(*) from bbs_posts");
	}

	public int getTopicCount()
	{
		return jdbcTemplate.queryForInt("select count(*) from bbs_topics");
	}

	public Board getBoardByName(String boardName, boolean initTopics)
	{
		return boardDao.getBoardByName(boardName, initTopics);
	}

	public List<Category> listAllCategorys()
	{
//		Query query = getSession().createQuery("select distinct category.* from Category category inner join fetch category.boards");
//		Query query = getSession().createQuery("from Category fetch all properties order by id desc");
		Query query = getSession().createQuery("from Category");
		List<Category> categories = query.list();
		for(Category category: categories)
		{
			Hibernate.initialize(category.getBoards());
		}
		System.err.println("categorys.size===>" + categories.size());
		return categories;
	}

	public void setBoardDao(BoardDao boardDao)
	{
		this.boardDao = boardDao;
	}
}
